package com.goldenautumn.prefabricate.activity.cart.dialog

import android.view.Gravity
import android.view.View
import android.view.Window
import android.view.WindowManager
import com.goldenautumn.prefabricate.R
import com.goldenautumn.prefabricate.databinding.DialogCidBinding
import qncx.external.common.widget.dialog.BaseDialog

class CidDialog constructor(val block: () -> Unit) : BaseDialog<DialogCidBinding>(qncx.external.common.R.style.BottomDialogs) {
    override val layoutRes: Int
        get() = R.layout.dialog_cid

    override fun onStart() {
        super.onStart()
        val window: Window? = dialog?.window
        val params: WindowManager.LayoutParams? = window?.attributes
        params?.dimAmount = dimAmount
        params?.width = WindowManager.LayoutParams.MATCH_PARENT
        if (height > 0) params?.height = height
        else params?.height = WindowManager.LayoutParams.WRAP_CONTENT
        params?.gravity = Gravity.BOTTOM
        window?.attributes = params
    }

    override suspend fun bindView(view: View): View {

        mBinding.closeBtn.setOnClickListener { dismiss() }

        mBinding.saveBtn.setOnClickListener {
            mBinding.saveBtn.postDelayed({
                mBinding.saveBtn.showSucceed()
                block()
                dismiss()
            },2000)
        }

        return view
    }
}